<template>
  <drawer :show="edit || record" :styles="{width:'750px'}" pos="right" tran="push" @change-show="changeDrawerShow">
    <div slot="drawer" style="height:100%">
      <edit v-if="edit" :data="selectTable" @getData="getData" @close="edit=false"></edit>
      <record v-if="record" :data="selectTable" @getData="getData" @close="record=false"></record>
    </div>
    <div class="app-container calendar-list-container">
      <div class="filter-container">
        <div class="filter-item">
          <span class="txt">类别:</span>
          </span>
          <typeselect v-model="search.authType" @input="getData">
            <el-option label="全部" value="-1" slot="option"></el-option>
          </typeselect>
        </div>
        <div class="filter-item">
          <span class="txt">状态:</span>
          </span>
          <span>
            <el-select v-model="search.status" placeholder="请选择" @change="getData">
              <el-option v-for="item in statusList" :key="item.value" :label="item.name" :value="item.value">
              </el-option>
            </el-select>
          </span>
        </div>
        <el-input class="filter-item" @keyup.enter.native="handleFilter" style="width: 200px;" placeholder="请输入关键词" v-model="search.keyword"></el-input>
        <div class="filter-item">
          <span class="txt">添加时间</span>
          <el-date-picker style="width: 240px;" value-format="timestamp" v-model="search.date" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </div>
        <el-button class="filter-item" v-waves icon="el-icon-search" @click="handleFilter">搜索</el-button>
      </div>
      <el-table v-loading="!pload" @selection-change="selectionChange" ref="multipleTable" border :data="tableData">
        <el-table-column label="类型" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{options[scope.row.authType]}}认证
          </template>
        </el-table-column>
        <el-table-column label="头像" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <img :src="scope.row.avatar" class="img">
          </template>
        </el-table-column>
        <el-table-column property="nickname" align="center" :label="search.authType === '2' ? '机构名称':'分析师名称'" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column property="names" align="center" :label="search.authType === '2' ? '机构法人':'真实姓名'" width="180" show-overflow-tooltip></el-table-column>
        <el-table-column property="phone" align="center" label="手机号" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="擅长领域" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.domains.join(',')}}
          </template>
        </el-table-column>
        <el-table-column label="风格标签" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.tags.join(',')}}
          </template>
        </el-table-column>
        <el-table-column label="审核状态" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag :type="{'10':'success','5':'danger','1':'warning'}[scope.row.status]" size="mini">{{{'1':'待审核','5':'审核不通过','10':'审核成功'}[scope.row.status]}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column property="classifyName" align="center" label="认证状态" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-tag :type="['danger','success'][scope.row.authenticationStatus]" size="mini">{{['未认证','已认证'][scope.row.authenticationStatus]}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="提交时间" align="center" show-overflow-tooltip>
          <template slot-scope="scope">
            {{scope.row.updateTime | parseTime('{y}-{m}-{d} {h}:{i}:{s}')}}
          </template>
        </el-table-column>
        <el-table-column align="center" label="审核记录" width="100">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleRecord(scope.$index, scope.row)">查看记录</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">查看审核</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-size="limit" :page-sizes="limits" background layout="sizes, prev, pager, next, jumper, total" :total="count">
        </el-pagination>
      </div>
    </div>
  </drawer>
</template>
<style lang="scss" scoped>
.img {
  display: block;
  margin: 0 auto;
  max-height: 50px;
}
</style>

<script>
import * as api from '@/utils/api'
import waves from '@/directive/waves' // 水波纹指令
import typeselect from './select'
export default {
  directives: {
    waves
  },
  data () {
    return {
      options: {
        '1': '专家',
        '2': '机构',
        '3': '达人'
      },
      statusList: [
        {
          name: '全部',
          value: '-1'
        },
        {
          name: '待审核',
          value: '1'
        },
        {
          name: '审核不通过',
          value: '5'
        },
        {
          name: '审核成功',
          value: '10'
        }
      ],
      tableData: [],
      search: {
        keyword: '',
        authType: '-1',
        status: '-1'
      },
      selection: [],
      selectTable: {},
      pload: false,
      record: false,
      edit: false,
      currentPage: 1,
      limit: 20,
      limits: [10, 20, 50, 100],
      count: 0
    }
  },
  components: {
    record: () => import('./record'),
    edit: () => import('./edit'),
    drawer: () => import('@/components/Drawer'),
    typeselect
  },
  created () {
    this.getData()
  },
  methods: {
    selectionChange (selection) {
      this.selection = selection
    },
    toggleSelection (s) {
      if (s === -1) {
        this.tableData.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row, true)
        })
      }
      if (s === 0) {
        this.tableData.forEach(row => {
          this.$refs.multipleTable.toggleRowSelection(row)
        })
      }
      if (s === 1) {
        this.$refs.multipleTable.clearSelection()
      }
    },
    handleAdd () {
      this.selectTable = { id: 0 }
      this.selectTable.method = 'add'
      this.edit = true
    },
    handleRecord (index, row) {
      this.selectTable = JSON.parse(JSON.stringify(row))
      this.selectTable.method = 'view'
      this.record = true
    },
    handleEdit (index, row) {
      this.selectTable = JSON.parse(JSON.stringify(row))
      this.selectTable.method = 'edit'
      this.edit = true
    },
    async getData () {
      if (this.search.date) {
        this.search.createTimeStart = this.search.date[0]
        this.search.createTimeEnd = this.search.date[1]
      } else {
        delete this.search.createTimeStart
        delete this.search.createTimeEnd
      }
      const data = this.JSONo(
        {
          pageNum: this.currentPage,
          pageSize: this.limit
        },
        this.search
      )
      this.pload = false
      const Datas = await api.getLtsAuditCert(data)
      this.tableData = Datas.list
      this.count = Datas.total
      this.pload = true
    },
    handleFilter () {
      this.currentPage = 0
      this.getData()
    },
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
      this.limit = val
      this.getData()
    },
    handleCurrentChange (val) {
      this.currentPage = val
      this.getData()
    },
    changeDrawerShow (state) {
      this.edit = state
      this.record = state
      console.log(state)
    }
  }
}
</script>
